package com.herench.bs.handler;


import com.herench.bs.agent.IInHosAgent;
import com.herench.bs.annotation.Handler;
import com.herench.bs.support.AbstractMessageHandler;
import com.herench.bs.support.RequestMessage;
import com.herench.bs.support.ResponseMessage;
import org.springframework.stereotype.Component;
import org.springframework.util.Assert;

import java.util.Map;


/**
 * Created by liuxiaohui on 2019/3/26.
 */
@Component
@Handler(code = "200103",name="患者入院申请查询：GetAppointsInHos()")
public class GetAppointsInHosHandler extends AbstractMessageHandler {

    @Override
    protected ResponseMessage innerHandler(RequestMessage requestMessage) throws Exception {
        ResponseMessage responseMessage = new ResponseMessage(requestMessage.getId());

        // **************** 微信前端传入的参数 ******************************************* Start
        // 系统编码：微信前端区分医院用
        String channelCode = requestMessage.getArgsPropertyStringValue("sysCode");
        // 身份证号
        String idNo = requestMessage.getArgsPropertyStringValue("idNo");
        Assert.notNull(idNo, "身份证号（idNo）：不可为空！");
        // 患者ID
        String patientId = requestMessage.getArgsPropertyStringValue("patientId");
        // 开始日期
        String startDate = requestMessage.getArgsPropertyStringValue("startDate");
        // 结束日期
        String endDate = requestMessage.getArgsPropertyStringValue("endDate");

        // **************** 微信前端传入的参数 ******************************************* End

        // 医院代码：微信后端区分医院用
        String hospitalCode = getCleverClinicContext().getHospitalCodeByChannelCode(channelCode);

        // 获取Bean信息
        IInHosAgent inHosAgent = getCleverClinicContext().getApplicationContext().getBean(IInHosAgent.class);
        // 设定入参
        Map<String, Object> res = inHosAgent.getAppointsInHos(channelCode, hospitalCode, idNo, patientId, startDate, endDate);

        // 设置应答信息
        responseMessage.setData(res);
        getPropertiesFromInvokerResultMap(responseMessage, res);

        return responseMessage;
    }
}
